package ${package.ServiceImpl};

import ${package.Entity}.${entity};
import ${package.Mapper}.${table.mapperName};
import ${package.Service}.${table.serviceName};
import ${superServiceImplClassPackage};
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;

import java.util.List;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * ${table.comment!} 服务实现类
 *
 * @author ${author}
 * @since ${date}
 */
<#assign keyPropertyType="">
<#list table.fields as field>
    <#if field.keyFlag>
        <#assign keyPropertyType="${field.propertyType}">
    </#if>
</#list>
@Service
<#if kotlin>
    open class ${table.serviceImplName} : ${superServiceImplClass}<${table.mapperName}, ${entity}>(), ${table.serviceName} {

    }
<#else>
public class ${table.serviceImplName} extends ${superServiceImplClass}<${table.mapperName}, ${entity}> implements ${table.serviceName} {

    /**
     * 分页列表
     *
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public IPage<${entity}> pageList(Page page, ${entity} ${entity?uncap_first}) {
        LambdaQueryWrapper<${entity}> lambdaQueryWrapper = new QueryWrapper<${entity}>().lambda();
        return page(page, lambdaQueryWrapper);
    }

    /**
     * 列表查询
     *
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    public List<${entity}> listByEntity(${entity} ${entity?uncap_first}) {
        LambdaQueryWrapper<${entity}> lambdaQueryWrapper = new QueryWrapper<${entity}>().lambda();
        return list(lambdaQueryWrapper);
    }

    /**
     * 详情
     *
     * @param id
     * @return
     */
    @Override
    public ${entity} selectById(${keyPropertyType} id) {
        return getById(id);
    }

    /**
     * 保存
     *
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean save${entity}(${entity} ${entity?uncap_first}) {
        return save(${entity?uncap_first});
    }

    /**
     * 修改
     *
     * @param ${entity?uncap_first}
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean modify(${entity} ${entity?uncap_first}) {
        return updateById(${entity?uncap_first});
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteById(${keyPropertyType} id) {
        if (id == null){
            return false;
        }
        LambdaUpdateWrapper<${entity}> lambdaUpdateWrapper = new UpdateWrapper<${entity}>().lambda()
            .eq(${entity}::getId, id)
            .set(${entity}::getDelFlg, 1);
        return update(lambdaUpdateWrapper);
    }
}
</#if>
